﻿@using Models
@model News

@{
    ViewBag.Title = "Update news";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<h2>Update news </h2>

<b> @ViewBag.Message</b> 
@if (ViewBag.Message != "The news will be published after viewing editor")
{
    using (Html.BeginForm())
    {
    @Html.ValidationSummary()
    <table>
        <tr>
            <td>
             @Html.LabelFor(x => x.Title)
            </td>
            <td>
            @Html.TextBoxFor(x => x.Title, new { value = Model.Title })
            </td>
        </tr>
        <tr>
            <td>
            @Html.LabelFor(x => x.Text)
            </td>
            <td>
             @Html.TextAreaFor(x => x.Text, new { value = Model.Text })
            </td>
        </tr>
        <tr>
            <td>
             @Html.LabelFor(x => x.Category)
            </td>
            <td>
             @{
             List<Category> categories = ViewBag.UpdateNewsCategories;
             @Html.DropDownListFor(x => x.Category, new SelectList(categories, "id", "name"))
}
            </td>
        </tr>
       <tr>
            <td>
            <label>Tags
            </label>
            </td>
            <td>
                @{
                    List<Tag> tags = ViewBag.UpdateNewsTags;
                        @Html.ListBoxFor(x=>x.TagsList, new MultiSelectList(tags, "Id", "Name"), new { Multiple = "multiple" })
                        }
            </td>
        </tr>
        <tr>
            <td colspan="2">
            <input type="hidden" name="rating" id="rating" value="@Model.Rating" />
            @Html.HiddenFor(x => x.UpdateDate, new { value = DateTime.Now })
            @Html.HiddenFor(x => x.PublishDate, new { value = Model.PublishDate })
            @Html.HiddenFor(x => x.Author, new { value = Model.Author })
    
            <input type="submit" name="subupdate" value="Update" />
            </td>
        </tr>
    </table>
    
    }
}
else
{
    @Html.ActionLink("To my news", "Index","AccountControll")
    ;
}